package ru.dadle8.service.impl.callback.workout;

import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.methods.ForwardMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import ru.dadle8.model.bot.BotConsts;
import ru.dadle8.model.bot.type.CallbackAction;
import ru.dadle8.service.impl.callback.AbstractCallbackService;

@Service
public class GetWorkoutCallbackServiceImpl extends AbstractCallbackService {
    @Override
    public int getAction() {
        return CallbackAction.GET_WORKOUT.getAction();
    }

    @Override
    public void processUpdate(Update update) throws TelegramApiException {
        ForwardMessage forwardMessage = ForwardMessage.builder()
                .messageId(getCallbackData().actionId())
                .chatId(getChatId())
                .fromChatId(BotConsts.CHANNEL_WITH_WORKOUTS).build();
        getBot().execute(forwardMessage);

        // avoid 'loading...'
        getBot().execute(getMessageHelper().sendAnswerCallbackQuery(getCallbackQuery()));
        // delete current menu message
        getBot().execute(getMessageHelper().sendDeleteMessage(getChatId(), getMessageId()));

        getStorage().clearState(getChatId());
    }
}
